package com.faner.fast.upms.controller;


import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.faner.fast.annotation.SysLog;
import com.faner.fast.base.PageDTO;
import com.faner.fast.upms.domain.dto.SysLogDTO;
import com.faner.fast.upms.model.SysLogDO;
import com.faner.fast.upms.service.SysLogService;
import com.faner.fast.util.PageUtil;
import com.faner.fast.util.R;
import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport;
import com.github.xiaoymin.knife4j.annotations.ApiSupport;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

/**
 * <p>
 * 日志表 前端控制器
 * </p>
 *
 * @author faner
 * @since 2021-01-22
 */
@Api(value = "log", tags = "系统-日志管理模块")
@ApiSupport(order = 30)
@RequiredArgsConstructor
@RestController
public class LogController {

    private final  SysLogService sysLogService;

    /**
     * 简单分页查询
     * @param page 分页对象
     * @param sysLog 系统日志
     * @return
     */
    @ApiOperation(value = "分页查询日志信息")
    @ApiOperationSupport(order = 10,author = "faner")
    @GetMapping("/log/page")
    public R<PageUtil<SysLogDO>> getLogPage(@Validated PageDTO page, SysLogDTO sysLog) {
        Page<SysLogDO> logByPage = sysLogService.getLogByPage(page, sysLog);
        return R.ok(PageUtil.resetPage(logByPage));
    }

    /**
     * 删除日志
     * @param id ID
     * @return success/false
     */
    @PreAuthorize("@pms.hasPermission('sys_log_del')")
    @ApiOperation(value = "删除日志")
    @ApiOperationSupport(order = 20,author = "faner")
    @PostMapping("/log/delete")
    public R removeById(@RequestParam Long id) {
        return R.ok(sysLogService.removeById(id));
    }


}

